package com.time.thread.basic;

/**
 * @program: tes
 * @description:
 * @author: xuejingjing
 * @create: 2021-10-18 16:34
 **/
public class MainThreadTest {
    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(new Thread());
        thread.start();
//        TestShunXu();

//        TestDuogexianchengshuijiao();


        //没看懂
//        ThreadTest();


/*************1.测试主线程******************************/
//             TestMainThread();
/*************1.测试主线程****************************/

        //勋章ID
//        List<Integer> medalIdList = medalLevelList.stream().filter(it -> null != it.getMedalId()).map(MedalLevelVo::getMedalId).collect(Collectors.toList());
        //星级
//        List<Integer> levelList = medalLevelList.stream().filter(it -> null != it.getLevel()).map(MedalLevelVo::getLevel).collect(Collectors.toList());


        /*****************2.测试第一种方式**************************************/
//        TestThreadNormal();
        /****************2.测试第一种方式*************************/
    }

    public static void TestShunXu() {
        //创建了10个线程，并开启。但是这10个线程的开启顺序并不是按照代码的执行顺序依次开启的。
        StartThread st1 = new StartThread(1);
        StartThread st2 = new StartThread(2);
        StartThread st3 = new StartThread(3);
        StartThread st4 = new StartThread(4);
        StartThread st5 = new StartThread(5);
        StartThread st6 = new StartThread(6);
        StartThread st7 = new StartThread(7);
        StartThread st8 = new StartThread(8);
        StartThread st9 = new StartThread(9);
        StartThread st10 = new StartThread(10);
        st1.start();
        st2.start();
        st3.start();
        st4.start();
        st5.start();
        st6.start();
        st7.start();
        st8.start();
        st9.start();
        st10.start();
    }

    public static void TestDuogexianchengshuijiao() throws InterruptedException {
        //接口指向实现类，多态
        Runnable runnable = new RunnableThread();
        Thread thread = new Thread(runnable);
        thread.setName("东风号");
        thread.start();
        for (int i = 0; i < 10; i++) {
            Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName()+"执行了");
        }
    }

    public static void TestThreadNormal() {
        //线程是一个子任务，CPU以不确定的方式，或者说是以随机的时间来调用线程中的run方法，所以就会出现先打印“运行结束！”后输出“MyThread”这样的结果了。
        BasicThread mythread = new BasicThread();
        mythread.start();
        System.out.println("运行结束！");
        //这也说明在使用多线程技术时，代码的运行结果与代码执行顺序或调用顺序是无关的。
    }

    public static void ThreadTest() throws InterruptedException {
        RandomThread randomThread = new RandomThread();
        randomThread.start();
        for (int i = 0; i < 10; i++) {
            int time = (int)(Math.random() *10000);
            Thread.sleep(time);
            System.out.println("main="+ Thread.currentThread().getName());
        }
    }

    public static void TestMainThread() {
        System.out.println(Thread.currentThread().getName());
    }
}
